# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=rebase
pkgver=4.4.4
pkgrel=2
pkgdesc="The Cygwin rebase distribution contains four utilities, rebase, rebaseall, peflags, and peflagsall"
arch=('i686' 'x86_64')
license=('custom')
url="https://www.cygwin.com/"
depends=('dash')
makedepends=('coreutils' 'git' 'grep' 'gzip' 'sed')
# options=('debug' '!strip')
source=(${pkgname}-${pkgver}::git://sourceware.org/git/cygwin-apps/rebase.git#tag=${pkgname}-${pkgver//./-}
        '001-rebase-4.4.1-msys2.patch'
        '002-rebaseall-add-python-exts.patch'
        '003-allow-non-database-mode-when-__CYGWIN__-__MSYS__.patch'
        '004-msys2-usr.patch'
        '005-make-verbose-give-a-reason.patch'
        '006-fix-some-errors.patch'
        '007-peflags-high-entropy-va.patch'
        'autorebase.bat'
        'autorebasebase1st.bat'
        'pacman-rec-filename-grep')
sha256sums=('SKIP'
            '6e25bfaae229062b20bed52b79824cfd1145de10c2ce50cd72b5a82fff9fbacf'
            'b06d561d82e7c32573082cf0207ca80275bab241c61debf2d3d8cc10cf79e31b'
            'b4823bfdc169744e05b9c71d513ef570b580ffc9dded4fa482ec644a557de56b'
            '825b24888bdf0e5e51691cda8a160905c6e40e991a6098664e2f892e56f87742'
            '01bc185bebc0bd8f4ac04207b0c07ee9f8da035eacf0e2ec8019150253597ee7'
            'a8b1b5cc6ab188d17dc9f353fa9c6593e2f82e998ce45a8662ff5f3294cb5f7c'
            'd8269f1f99c968afe20eae020de92dae12483cefc03e0393aa1367a92c61d1dc'
            '8e4099a29107a1d03031b198c3d142bbc31a40ff19298d6e099d9bcffd31b1b0'
            '0aed2c3a36e1926af4b0c914d208d4846bb0082d2f4886e6bb17d4b8b7fb42d5'
            '2ca1e58fb1d2625e93224d0d1ca3b86944030ef2572289222b42ccc2387033fd')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  patch -p1 -i ${srcdir}/001-rebase-4.4.1-msys2.patch
  patch -p1 -i ${srcdir}/002-rebaseall-add-python-exts.patch
  patch -p1 -i ${srcdir}/003-allow-non-database-mode-when-__CYGWIN__-__MSYS__.patch
  patch -p1 -i ${srcdir}/004-msys2-usr.patch
  patch -p1 -i ${srcdir}/005-make-verbose-give-a-reason.patch
  patch -p1 -i ${srcdir}/006-fix-some-errors.patch
  patch -p1 -i ${srcdir}/007-peflags-high-entropy-va.patch

  if check_option "strip" "n"; then
    sed -i "s/ -s//g" Makefile.in
  fi
  autoreconf -fi
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  ./configure --prefix=/usr \
    --sysconfdir=/etc \
    CXXFLAGS="${CXXFLAGS} -static -static-libgcc -static-libstdc++" \
    CFLAGS="${CFLAGS} -static -static-libgcc"

  make
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  make DESTDIR=${pkgdir} install
  cp -f ${srcdir}/autorebase.bat ${pkgdir}
  cp -f ${srcdir}/autorebasebase1st.bat ${pkgdir}
  cp -f ${srcdir}/pacman-rec-filename-grep ${pkgdir}/usr/bin
}
